<?php

/**
 * 下游通知商品接收处理结果
 */
namespace App\Service\OrderService\OrderInterfaceService;;

use App\Service\Code\Normal;
use App\Service\BaseService;
use App\Model\PssModel\MerchantGoodsSyncLog;

class SyncUserGoodsCountService extends BaseService
{

    /**
     * 支付结果掉用
     * @param array $message
     */
    public function index( $param = [] )
    {
        $bid            = $param['binfo']['bid'];
        $requestData    = $param['requestData'];
        if( empty($requestData['message_id']) ) {
            return Normal::returnCode(Normal::FAIL,"except param requestData.message_id");
        }
        
        if( !isset($requestData['goods_count']) ) {
            return Normal::returnCode(Normal::FAIL,"except param requestData.goods_count");
        }
        
        $where = [
            'bid'   => $bid,
            'id'    => $requestData['message_id'],
        ];
        $res = MerchantGoodsSyncLog::instance()->info($where);
        if( empty($res) ) {
            return Normal::returnCode(Normal::FAIL,"当前消息不存在，请核对");
        }
        
        $res = MerchantGoodsSyncLog::instance()->where($where)->update([
            'sync_user_count'   => $requestData['goods_count'],
            'sync_notify_time'  => time(),
        ]);
        if( $res ) {
            return Normal::returnCode(Normal::SUC,"处理完成");
        }
        return Normal::returnCode(Normal::FAIL,"通知失败");
    }
}
